home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / tools / c2latex.lha / c++2latex / getopt1.c < prev    next >
C/C++ Source or Header  |  1993-08-08  |  3KB  |  146 lines

  1. * Getopt for GNU.
  2.    Copyright (C) 1987, 1989 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 1, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18.  
  19.  
  20. include "getopt.h"
  21.  
  22. nt
  23. etopt_long (argc, argv, options, long_options, opt_index)
  24.      int argc;
  25.      char **argv;
  26.      char *options;
  27.      struct option *long_options;
  28.      int *opt_index;
  29.  
  30.   int val;
  31.   _getopt_long_options = long_options;
  32.   val = getopt (argc, argv, options);
  33.   if (val == 0)
  34.     *opt_index = option_index;
  35.   return val;
  36.  
  37.  
  38. * Like getopt_long, but there are no short options.  That is,
  39.    '-' as well as '+' indicates a long option.  Of course, long_options
  40.    can contain single character options but '-ab' is not the same as
  41.    '-a -b'.  */
  42. nt getopt_long_only (argc, argv, options, long_options, opt_index)
  43.      int argc;
  44.      char **argv;
  45.      char *options;
  46.      struct option *long_options;
  47.      int *opt_index;
  48.  
  49.   int val;
  50.   _getopt_long_options = long_options;
  51.   _getopt_long_only = 1;
  52.   val = getopt (argc, argv, options);
  53.   if (val == 0)
  54.     *opt_index = option_index;
  55.   return val;
  56.  
  57.      
  58.  
  59. ifdef TEST
  60.  
  61. include <stdio.h>
  62.  
  63. nt
  64. ain (argc, argv)
  65.      int argc;
  66.      char **argv;
  67.  
  68.   char c;
  69.   int digit_optind = 0;
  70.  
  71.   while (1)
  72.     {
  73.       int this_option_optind = optind;
  74.       char *name = '\0';
  75.       int option_index = 0;
  76.       static struct option long_options[]
  77.     = {{ "add", 1, 0, 0 },
  78.        { "append", 0, 0, 0 },
  79.        { "delete", 1, 0, 0 },
  80.        { "verbose", 0, 0, 0 },
  81.        { "create", 0, 0, 0 },
  82.        { "file", 1, 0, 0 },
  83.        { 0, 0, 0, 0}};
  84.  
  85.       c = getopt_long (argc, argv, "abc:d:0123456789",
  86.                long_options, &option_index);
  87.       if (c == EOF)
  88.     break;
  89.     switch (c)
  90.       {
  91.       case 0:
  92.         printf ("option %s", (long_options[option_index]).name);
  93.         if (optarg)
  94.           printf (" with arg %s", optarg);
  95.         printf ("\n");
  96.         break;
  97.  
  98.       case '0':
  99.       case '1':
  100.       case '2':
  101.       case '3':
  102.       case '4':
  103.       case '5':
  104.       case '6':
  105.       case '7':
  106.       case '8':
  107.       case '9':
  108.         if (digit_optind != 0 && digit_optind != this_option_optind)
  109.           printf ("digits occur in two different argv-elements.\n");
  110.         digit_optind = this_option_optind;
  111.         printf ("option %c\n", c);
  112.         break;
  113.  
  114.       case 'a':
  115.         printf ("option a\n");
  116.         break;
  117.  
  118.       case 'b':
  119.         printf ("option b\n");
  120.         break;
  121.  
  122.       case 'c':
  123.         printf ("option c with value `%s'\n", optarg);
  124.         break;
  125.  
  126.       case '?':
  127.         break;
  128.  
  129.       default:
  130.         printf ("?? getopt returned character code 0%o ??\n", c);
  131.       }
  132.     }
  133.  
  134.   if (optind < argc)
  135.     {
  136.       printf ("non-option ARGV-elements: ");
  137.       while (optind < argc)
  138.     printf ("%s ", argv[optind++]);
  139.       printf ("\n");
  140.     }
  141.  
  142.   return 0;
  143.  
  144.  
  145. endif /* TEST */
  146.